package cn.edu.ncu.housinghub.controller.admin;

import cn.edu.ncu.housinghub.entity.house.PropertyVerification;
import cn.edu.ncu.housinghub.service.AdminHouseService;
import cn.edu.ncu.housinghub.service.HouseService;
import cn.edu.ncu.housinghub.vo.Result;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房源审核、下架、违规处理
 */
@RestController
@Validated
@RequestMapping("/admin/house")
public class AdminHouseController {
    @Autowired
    private AdminHouseService adminHouseService;
    @Autowired
    private HouseService houseService;

    /*
    * 管理员查看所有房产验证信息
     */
    @GetMapping("/getAllPropertyVerification")
    public Result getAllPropertyVerification(){
        List<PropertyVerification> propertyVerifications = adminHouseService.findAllPropertyVerification();
        return Result.success(propertyVerifications);
    }

    /**
     * 管理员通过房产信息认证
     */
    @PostMapping("/passVerify/{propertyVerifyId}")
    public Result passVerify(@PathVariable Long propertyVerifyId){
        adminHouseService.modifyPropertyVerificationStatus(propertyVerifyId);
        return Result.success();
    }


    /**
     * 管理员批量通过房产信息认证
     */
    @PostMapping("/batchPassVerify")
    public Result batchPassVerify(@RequestBody List<Long> propertyVerifyIds){
        adminHouseService.modifyBatchPassVerify(propertyVerifyIds);
        return Result.success();
    }


    /**
     * 管理员驳回房产信息认证
     */
    @PostMapping("/rejectPropertyVerification/{propertyVerifyId}")
    public Result rejectPropertyVerification(@RequestBody @NotBlank(message = "拒绝原因不能为空")  String reason, @PathVariable("propertyVerifyId") Long propertyVerifyId){
        adminHouseService.modifyRejectVerify(propertyVerifyId,reason);
        return Result.success();
    }
}
